package nccu.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.compass.annotations.Searchable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.io.Serializable;
import java.util.Date;

/**
 * This class represents the basic "submission" object that allows for xml file submission
 * persistence and management.
 *
 * @author <a href="mailto:chris.oberle@gmail.com">Chris Oberle</a>
 */
@Embeddable
@Searchable(root = false)
public class Submission extends BaseObject implements Serializable {

    private static final long serialVersionUID = 3617859655331969141L;

    @XStreamAlias("SubmissionStatus")
    private String status;  // required

    @XStreamAlias("DateSubmission")
    private Date createDate;// required

    @XStreamAlias("CertifierFirstName")
    private String certifierFirstName; // required

    @XStreamAlias("CertifierLastName")
    private String certifierLastName; // required

    @Column(name = "status", length = 100, nullable = false, unique = false)
    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @Column(name = "create_date", length = 100, nullable = false, unique = false)
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Column(name = "first_name", nullable = false, length = 100, unique = false)
    public String getCertifierFirstName() {
        return certifierFirstName;
    }

    public void setCertifierFirstName(String certifierFirstName) {
        this.certifierFirstName = certifierFirstName;
    }

    @Column(name = "last_name", nullable = false, length = 100, unique = false)
    public String getCertifierLastName() {
        return certifierLastName;
    }

    public void setCertifierLastName(String certifierLastName) {
        this.certifierLastName = certifierLastName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Submission)) return false;

        Submission that = (Submission) o;

        if (!certifierFirstName.equals(that.certifierFirstName)) return false;
        if (!certifierLastName.equals(that.certifierLastName)) return false;
        if (!createDate.equals(that.createDate)) return false;
        if (!status.equals(that.status)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = status.hashCode();
        result = 31 * result + createDate.hashCode();
        result = 31 * result + certifierFirstName.hashCode();
        result = 31 * result + certifierLastName.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Submission{" +
                "status='" + status + '\'' +
                ", createDate=" + createDate +
                ", certifierFirstName='" + certifierFirstName + '\'' +
                ", certifierLastName='" + certifierLastName + '\'' +
                '}';
    }
}
